package com.health.auth.config;

import com.health.auth.servlet.ChangeRequestWrapper;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

// 对一些非必要参数进行装填需 目前没有多客户端的必要
@Order
@WebFilter("/oauth/token")
// 配置过滤器使用这个注解是不正确的 Component 会重新刷一遍过滤器这样的化会过滤所有
@Component
public class LoadFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        ChangeRequestWrapper changeRequestWrapper = new ChangeRequestWrapper((HttpServletRequest) servletRequest);
        Map<String, String[]> parameterMap = new HashMap<>(changeRequestWrapper.getParameterMap());
        parameterMap.put("username",new String[]{"tidudada"});
        parameterMap.put("grant_type",new String[]{"password"});
        parameterMap.put("scopes",new String[]{"server"});
        changeRequestWrapper.setParameterMap(parameterMap);
        filterChain.doFilter(changeRequestWrapper,servletResponse);

    }

}
